package com.cloud.bc.controller.pc;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloud.bc.controller.BaseController;
import com.cloud.bc.model.domain.UserInfo;
import com.cloud.bc.model.request.LikeRequest;
import com.cloud.bc.model.response.UserGiftResponse;
import com.cloud.bc.service.BcUserGiftsService;
import com.cloud.bc.service.BcUsersService;
import com.cloud.bc.util.JiaoYouPageHelper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

//PC礼物
@Controller
@AllArgsConstructor
@RequestMapping("center/gift")
public class PcCenterGiftController extends BaseController {

    private final BcUserGiftsService bcUserGiftsService;
    private final BcUsersService bcUsersService;

    /**
     * 礼物 我送出的礼物
     */
    @GetMapping("")
    public ModelAndView index(HttpServletRequest request, HttpServletResponse response,
                              LikeRequest req) {
        ModelAndView view = baseView(request, "我送出的礼物-用户中心", "pc/center/gift/index");
        view.addObject("bodyCss", "page_manage page_manage_gift");
        UserInfo userInfo = bcUsersService.getUserInfo(request);
        Page p = new Page();
        p.setCurrent(Convert.toInt(req.getPage(), 0) <= 0 ? 1 : req.getPage());
        List<UserGiftResponse> list = bcUserGiftsService.getGiveGift(p, userInfo.getId());
        view.addObject("giftList", list);
        JiaoYouPageHelper jiaoYouPageHelper = new JiaoYouPageHelper();
        view.addObject("page", jiaoYouPageHelper.getBcPageHTML(p, request));
        return view;
    }

    /**
     * 礼物 我收到的礼物
     */
    @GetMapping("giftme")
    public ModelAndView giftme(HttpServletRequest request, HttpServletResponse response,
                               LikeRequest req) {
        ModelAndView view = baseView(request, "我收到的礼物-用户中心", "pc/center/gift/giftme");
        view.addObject("bodyCss", "page_manage page_manage_gift");
        UserInfo userInfo = bcUsersService.getUserInfo(request);
        Page p = new Page();
        p.setCurrent(Convert.toInt(req.getPage(), 0) <= 0 ? 1 : req.getPage());
        List<UserGiftResponse> list = bcUserGiftsService.getReceiveGift(p, userInfo.getId());
        view.addObject("giftList", list);
        JiaoYouPageHelper jiaoYouPageHelper = new JiaoYouPageHelper();
        view.addObject("page", jiaoYouPageHelper.getBcPageHTML(p, request));
        return view;
    }

}
